package com.dm.yyxr.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dm.yyxr.pojo.Supplystatus;
import com.dm.yyxr.pojo.dto.SupplystatusDto;
import com.dm.yyxr.service.SupplystatusService;
import com.dm.yyxr.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@CrossOrigin
@RequestMapping("/supplystatus")
public class SupplystatusController {
    @Autowired
    SupplystatusService supplystatusService;
    //添加供电审核表
    @PostMapping("/addSupplystatus")
    public Result<Object> addSupplystatus(@RequestBody Supplystatus supplystatus){
        //创建供电审核表的申请时间
        supplystatus.setSupplytime(new Date());
        //将前端传入的审核表的数据（supplystatus）添加到数据库中
        supplystatusService.save(supplystatus);
        //返回正确信息
        return Result.ok();
    }
    //查询供电审核表
    @GetMapping("/getSupplystatus")
    public Result<Object> getSupplystatus(@RequestParam Integer pageNo){
        //从数据库中获取供电审核表的分页数据
        Page<SupplystatusDto> page = supplystatusService.getSupplystatus(pageNo);
        //返回分页数据
        return Result.ok(page);
    }
    //设置供电审核表信息
    @PostMapping("/setSupplystatus")
    public Result<Object> setSupplystatus(@RequestBody Supplystatus supplystatus){
        //更新供电审核表，填补供电审核表的审核时间
        supplystatusService.setSupplyStatus(supplystatus);
        return Result.ok();
    }
}
